<?php
class TimExtend extends Tim
{
	public function selBiaya($id_provinsi,$id_kary){
		$sql = "select k.*,tp.nama_type_dinas,bp.biaya_harian,bp.biaya_penginapan,bp.id_provinsi from karyawan k
				inner join type_dinas tp on tp.id_type_dinas = k.id_type_dinas
				inner join biaya_prov bp on bp.id_type_dinas = k.id_type_dinas
				where bp.id_provinsi = '$id_provinsi'
				and k.id_kary = '$id_kary'";
        $result = Yii::app()->db->createCommand($sql)->queryAll();
		return $result;
	}
	
	public function editKegiatan($id)
	{
		$criteria=new CDbCriteria;
		
		$criteria->alias = 't';
        $criteria->select = 't.id_tim,
								t.id_kegiatan,
								t.id_kary,
								t.id_transport,
								t.biaya_trans,
								t.biaya_trans,
								t.airportax,
								t.riil,
								DATE_FORMAT(t.tgl_mulai,"%d/%m/%Y") as tgl_mulai,
								DATE_FORMAT(t.tgl_berakhir,"%d/%m/%Y") as tgl_berakhir,
								t.descrip_tim,
								k.nip,
								k.nama,
								keg.nama_kegiatan,
								tran.description,
								prov.nama_prov,
								(to_days(t.tgl_berakhir)-to_days(t.tgl_mulai))as hari,
								(
									select bp.biaya_harian from biaya_prov bp
									where bp.id_provinsi = t.id_provinsi
									and bp.id_type_dinas = k.id_type_dinas
								)as  biaya_harian,
								(
									select bp.biaya_penginapan from biaya_prov bp
									where bp.id_provinsi = t.id_provinsi
									and bp.id_type_dinas = k.id_type_dinas
								)as  biaya_penginapan'; 
		$criteria->join = ' left join karyawan k on k.id_kary = t.id_kary
							left join kegiatan keg on keg.id_kegiatan = t.id_kegiatan
							left join transport tran on tran.id_transport = t.id_transport
							left join provinsi prov on prov.id_provinsi = t.id_provinsi';
		$criteria->condition ="t.id_kegiatan = '$id'";
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}